﻿using RestSharp;
using ServiceStack.Text;
using System;
using System.Web;
using Ymatou.ServiceCenter;
using Ymatou.User.Dto.Auth;
using YmtAuth.AppService;
using YmtAuth.Domain.Shard;
using YmtAuth.Dto;
using YmtSystem.CrossCutting;
using ResetService = ServiceStack.Service;

namespace YmtAuth.Web.Handlerv2
{
    
    public class UserBillsHandler : ResetService
    {
        private IUserBillsAppService BillsAppService { get { return LocalServiceLocator.GetService<IUserBillsAppService>(); } }
        //获取用户凭据
        [ServiceRegister("/json/reply/UserBillsRequestDto", Method.GET)]
        public object Get(UserBillsRequestDto request)
        {
            HttpContext.Current.Request.Headers.Add(YmtUserKey.RequestId, Guid.NewGuid().ToString("N"));
            HttpContext.Current.Request.Headers.Add(YmtAuthSafeConstant.ApiId, YmtAuthSafeConstant.Api_login);

            return BillsAppService.GetUserBills(request, Request);
        }

        //修改凭据
        [ServiceRegister("/json/reply/UserBillsRequestDto", Method.POST)]
        public object Post(UserBillsRequestDto request)
        {
            YmatouLoggingService.Debug("UserBillsRequestDto {0}", JsonSerializer.SerializeToString<UserBillsRequestDto>(request));
            return BillsAppService.Update(request);
        }

        [ServiceRegister("/json/reply/LockUserRequestDto", Method.POST)]
        public object Post(LockUserRequestDto request)
        {
            return BillsAppService.LockUser(request);
        }

        [ServiceRegister("/json/reply/UnLockUserRequestDto", Method.POST)]
        public object Post(UnLockUserRequestDto request)
        {
            return BillsAppService.UnLockUser(request);
        }

        [ServiceRegister("/json/reply/LockIpRequestDto", Method.POST)]
        public object Post(LockIpRequestDto request)
        {
            return BillsAppService.LockIp(request);
        }

        [ServiceRegister("/json/reply/UnLockIpRequestDto", Method.POST)]
        public object Post(UnLockIpRequestDto request)
        {
            return BillsAppService.UnLockIp(request);
        }

        [ServiceRegister("/json/reply/UserLockStatusRequestDto", Method.GET)]
        public object Get(UserLockStatusRequestDto request)
        {
            return BillsAppService.GetUserLockStatus(request);
        }

        [ServiceRegister("/json/reply/IpLockStatusRequestDto", Method.GET)]
        public object Get(IpLockStatusRequestDto request)
        {
            return BillsAppService.GetIpLockStatus(request);
        }
    }
}